package JavaEE.io;
import java.io.File;
import java.io.IOException;
import java.util.*;

// 文件类 File
public class Demo1 {
    public static void main(String[] args) throws IOException {
        // 绝对路径~
        File file1 = new File("D:/test12.txt");
        // 相对路径 -> "基准路径由编译器决定"
        File file2 = new File("./test12.txt");

        // 演示方法:
        // getParent: 返回File对象的父目录文件路径
        System.out.println("file1: " + file1.getParent());
        // getName: 返回File对象的纯文件名称
        System.out.println("file1: " + file1.getName());
        // getPath: 返回File对象的文件路径
        System.out.println("file1: " + file1.getPath());
        // getAbsolutePath: 返回File对象的绝对路径
        System.out.println("file1: " + file1.getAbsolutePath());
        // getCanonicalPath: 返回File对象"修饰过"的绝对路径
        System.out.println("file1: " + file1.getCanonicalPath());
        // exists: 返回该对象是否存在
        System.out.println("file1: " + file1.exists());
        // isDirectory: 返回该对象是否为"目录"(通俗叫文件夹,目录为专业叫法)
        System.out.println("file1: " + file1.isDirectory());
        // isFile: 返回该对象是否为"普通文件"/"非目录"
        System.out.println("file1: " + file1.isFile());
        // createNewFile: 根据File对象,自动创建一个空文件夹,创建成功返回true
        System.out.println("file1: " + file1.createNewFile());
        // delete: 根据File对象,删除该文件,成功后返回true
        System.out.println("file1: " + file1.delete());
        // deleteOnExit: 根据File对象,标注文件将被删除,删除动作会到JVM运行结束时才运行
        file1.deleteOnExit();

        System.out.println("-----------------------------------------------------------");

        System.out.println("file2: " + file2.getParent());
        System.out.println("file2: " + file2.getName());
        System.out.println("file2: " + file2.getPath());
        System.out.println("file2: " + file2.getAbsolutePath());
        System.out.println("file2: " + file2.getCanonicalPath());
        System.out.println("file2: " + file2.exists());
        System.out.println("file2: " + file2.isDirectory());
        System.out.println("file2: " + file2.isFile());
        System.out.println("file2: " + file2.createNewFile());
        System.out.println("file2: " + file2.delete());
        file2.deleteOnExit();
    }
}
